option(USE_OPENCV "Use opencv" ON)
if(NOT USE_OPENCV)
    return()
endif()

PROJECT(OpenCV)

find_package(OpenCV COMPONENTS core imgproc video) # videoio)
IF(OpenCV_FOUND)
    list(APPEND RABBITIM_DEFINES RABBITIM_USE_OPENCV)
    LIST(APPEND RABBITIM_LIBS ${OpenCV_LIBS})
    #INSTALL_TARGETS(TARGETS ${OpenCV_LIBS})
else()
    return()
ENDIF()
message("== Plug OpenCV:${OpenCV_FOUND}")

file(RELATIVE_PATH PLUGIN_RELATIVE_DIR ${CMAKE_SOURCE_DIR}/Plugin ${CMAKE_CURRENT_SOURCE_DIR})
if(NOT ANDROID)
    set(PLUGIN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/plugins/${PLUGIN_RELATIVE_DIR})
    set(PLUGIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/plugins/${PLUGIN_RELATIVE_DIR})
endif()

ADD_PLUGIN_TARGET(
    SOURCE_FILES ConverFormatOpenCV.cpp ConverFormatOpenCV.h
    INCLUDE_DIRS $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/Src>
        $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/Plugin>
    PRIVATE_DEFINITIONS ${RABBITIM_DEFINES} OpenCV_VERSION_MAJOR=${OpenCV_VERSION_MAJOR}
    PRIVATE_LIBS RabbitIm ${OpenCV_LIBS}
    OUTPUT_DIR ${PLUGIN_OUTPUT_DIR}
    INSTALL_DIR ${PLUGIN_INSTALL_DIR}
    )
